package com.passioneffect.widgets {
	import flash.display.DisplayObjectContainer;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	import com.passioneffect.appLayout.AppLayout;	

	/**
	 * @author Passion Effect
	 */
	public class OverHandlerLayout {

		private var at : DisplayObjectContainer;
		private var layout : AppLayout;
		private var outHandler : Function;
		private var overHandler : Function;
		private var overed:Boolean;
		
		public function OverHandlerLayout(layout:AppLayout,at:DisplayObjectContainer,overHandler:Function,outHandler:Function) {
			this.at=at;
			this.layout=layout;
			this.overHandler=overHandler;
			this.outHandler=outHandler;
			overed=false;
			at.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
		}
		
		private function moveHandler(event : MouseEvent) : void {
			
			var rect:Rectangle=layout.rect;
			if(rect.contains(at.mouseX, at.mouseY)){
				if(overed)return;
				overed=true;
				if(overHandler!=null)overHandler(layout);
			}else{
				if(!overed)return;
				overed=false;
				if(outHandler!=null)outHandler(layout);
			}
		}
		
		
	}
}
